package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	// 数组
	array := [5]int{1, 2, 3, 4, 5}
	fmt.Printf("array %+v\n", array)

	// 切片
	slice := []int{1, 2, 3, 4, 5}
	fmt.Printf("slice %+v\n", slice) // 怎么看切片和数组？前面那个方括号没数字的就是切片，有就是数组

	slice1 := new([]int)
	slice2 := make([]int, 0)      // 后面数字必填
	slice3 := make([]int, 10)     // 10个元素 容量也为10
	slice4 := make([]int, 10, 20) // 10个元素 容量为20
	fmt.Printf("slice1 %+v\n", slice1)
	fmt.Printf("slice2 %+v\n", slice2)
	fmt.Printf("slice3 %+v\n", slice3)
	fmt.Printf("slice4 %+v\n", slice4)

	// map
	map1 := make(map[string]string)     // 无指定容量
	map2 := make(map[string]string, 10) // 指定容量10

	fmt.Printf("map1 %+v\n", map1)
	fmt.Printf("map2 %+v\n", map2)

	board := make([][]int, 3, 3)
	for i := 0; i < 3; i++ {
		board[i] = make([]int, 3, 3)
	}

	fmt.Printf("board %+v\n", board)

	islands := canCross([]int{0, 1, 3, 5, 6, 8, 12, 17})
	fmt.Println(islands)

}

func canCross(stones []int) (ans bool) {
	var dfs func(i, step int)
	dfs = func(i, step int) {
		if i == len(stones)-1 {
			ans = true
			return
		}
		if i > len(stones)-1 || step <= 0 {
			return
		}

		for j := i + 1; j < len(stones); j++ {
			if (stones[i] + step) == stones[j] {
				dfs(j, step+1)
				dfs(j, step-1)
				continue
			}
		}
	}

	dfs(0, 1)
	return ans
}

func floor(nums []int, k int) int {
	sort.Ints(nums)
	for i := len(nums) - 1; i >= 0; i-- {
		if nums[i] <= k {
			return nums[i]
		}
	}
	return 0
}

func conv(b byte) int {
	if b == '1' {
		return 1
	}
	return 0
}

func maxList(nums []int) int {
	return 1
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

type ListNode struct {
	Val  int
	Next *ListNode
}
type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func isValidBST(root *TreeNode) bool {

	pre := math.MinInt32
	var inorder func(node *TreeNode)
	inorder = func(node *TreeNode) {
		if node == nil {
			return
		}
		inorder(node.Left)

		if pre > node.Val {

		}

		inorder(node.Right)
	}

	inorder(root)
	return true
}
